package managedbean;
import fr.afcepf.atod16.groupe1.projet1.exception.ErreurLoginConnexion;
import fr.afcepf.atod16.groupe1.projet1.dto.client.DtoCompteClient;
import fr.afcepf.atod16.groupe1.projet1.service.ServiceCompteClientLocal;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;


@ManagedBean(name="mbeanLogin")
@SessionScoped
public class MbLogin {
   private Boolean logged;
   private Boolean erreurConnexion = false;
    private DtoCompteClient compteClient;
    private String email;
    private String password;

    @EJB 
    ServiceCompteClientLocal serviceClient;
    
    public MbLogin() {
        logged = false;
    }
   
    public String seConnecter(){
        erreurConnexion = false;
        DtoCompteClient client;
        try {
            client = serviceClient.seConnecter(email, password);
        if(client != null){
            compteClient = client;
            logged = true;
        }
         } catch (ErreurLoginConnexion ex) {
            erreurConnexion = true;
        }
        return "";
    }

    public String seDeconnecter(){
        logged = false;
        compteClient = null;
        email = "";
        return "";
    }
    public Boolean getLogged() {
        return logged;
    }

    public void setLogged(Boolean logged) {
        this.logged = logged;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
       
    public DtoCompteClient getCompteClient() {
        return compteClient;
    }

    public void setCompteClient(DtoCompteClient compteClient) {
        this.compteClient = compteClient;
    }

    public Boolean getErreurConnexion() {
        return erreurConnexion;
    }

    public void setErreurConnexion(Boolean erreurConnexion) {
        this.erreurConnexion = erreurConnexion;
    }
    
}
